﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DevComponents.DotNetBar.Controls;
using System.ComponentModel;
using System.Windows.Forms;

namespace STLGROUP.Controls
{
    public class STLTextBox : TextBox
    {
        private bool _onlyNumber = false;
        private bool _isUpperChar = false;

        [Browsable(true)]
        [Category("Number Only")]
        public bool OnlyNumber
        {
            get { return _onlyNumber; }
            set { _onlyNumber = value; }
        }

        [Browsable(true)]
        [Category("IsUpperChar")]
        public bool IsUppderChar
        {
            get { return _isUpperChar; }
            set { _isUpperChar = value; }
        }

        public STLTextBox()
        {
            this.Size = new System.Drawing.Size(100, this.Font.Height + 100);
            this.KeyPress += new System.Windows.Forms.KeyPressEventHandler(STLTextBox_KeyPress);
            this.Leave += new EventHandler(STLTextBox_Leave);
        }

        private void STLTextBox_Leave(object sender, EventArgs e)
        {
            if (this.Text.Length > 0)
            {
                if (_isUpperChar)
                {
                    string str = this.Text;
                    this.Text = str.ToUpper();
                }
            }
        }

        private void STLTextBox_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
        {
            if (_onlyNumber == true)
            {
                if (char.IsLetter(e.KeyChar) ||
                    char.IsSymbol(e.KeyChar) ||
                    char.IsWhiteSpace(e.KeyChar) ||
                    char.IsPunctuation(e.KeyChar))
                {
                    e.Handled = true;
                }
            }
        }

    }
}
